package entities

import "mlgmd.com/hearsay/base"

type User struct {
	Id             int    `xorm:"pk autoincr" json:"id"`
	DeviceCode     string `json:"deviceCode"` // 设备码，初次访问时生成
	Username       string `json:"username"`
	Password       string `json:"password"`
	Salt           string `json:"salt"`
	Contact        string `json:"contact"` // 联系方式
	UserProfile    `xorm:"extends"`
	Roles          string `json:"roles"`
	Coin           int    `json:"coin"`
	Weight         int    `json:"weight"`
	WeightBase     int    `json:"weightBase"`
	HearsayMaxCoin int    `json:"hearsayMaxCoin"`
	HearsayCount   int    `json:"hearsayCount"`
	RewardCount    int    `json:"rewardCount"`
	CommentCount   int    `json:"commentCount"`
	//HearsayFilter          int    `json:"hearsayFilter"`          // 用来过滤掉已经推荐过的传闻(crc32)
	//HearsayFilterCount     int    `json:"hearsayFilterCount"`     // 已过滤的传闻数量
	//HearsayFilterNext      int    `json:"hearsayFilterNext"`      // 即将被过滤掉的传闻(crc32)
	//HearsayFilterNextCount int    `json:"hearsayFilterNextCount"` // 即将被过滤掉的传闻数量
	Notice        string `xorm:"text" json:"notice"` // 管理员:提醒
	Blocked       bool   `json:"blocked"`            // 已屏蔽
	ReferrerId    int    `json:"referrerId"`         // 推荐人
	ReferrerError string `json:"referrerError"`      // 推荐时的异常
	CreatedTime   int64  `json:"createdTime"`
}

func (u User) Key(k string) int {
	return u.Id
}

func (u *User) Mask() {
	u.Password = ""
	u.Salt = ""
	u.Coin = 0
}

type UserProfile struct {
	Avatar    string `json:"avatar"`
	Nickname  string `json:"nickname"`
	Signature string `xorm:"text" json:"signature"`
	Gender    int    `json:"gender"`   // 性别:0,保密;1,男;2,女
	Publicly  bool   `json:"publicly"` // 可公开
}

type UserComment struct {
	Comment `xorm:"extends"`
}

func init() {
	base.Must(base.DB.Sync(&User{}, &UserComment{}))
}
